<?php
if ($action=="del"){
	delgoodscart($id);
	header("location:mygoodscart.php");exit();
}
if ($action=="editnum"){
	$sql="select * from {$db_prefix}product where id='".$id."'";
	$rs=$db->get_one($sql);
	editgoodscart($rs["id"],$rs["productname"],floatval($num),$rs["price"],$rs["pv"]);
	echo "<script>alert('修改成功');location.href='mygoodscart.php';</script>";exit();
}

if ($action=="order"){
	$modtime=time();
	$goodscartstr=getgoodscart();
	$price=0;$pv=0;

	$goodscartary=explode("|",$goodscartstr);
  
	foreach($goodscartary as $value_1){
		$value_1_ary=explode(",",$value_1);
		$sql="select * from {$db_prefix}product where id='".$value_1_ary[0]."'";
		$rs=$db->get_one($sql);
		$price+=$rs["price"]*floatval($value_1_ary[2]);
		$pv+=$rs["pv"]*floatval($value_1_ary[2]);
	}

    $sql="select rank,isdp from {$db_prefix}users where username='".$_SESSION["glo_username"]."'";
    $rr=$db->get_one($sql);

    $zhekou=0;
	echo "<script>location.href='address.php';</script>";exit();
}
?>
    <link rel="stylesheet" href="../css/datalist.css" type="text/css">
<script language="javascript">
	function goodsedit(id){
		num=document.getElementById("num_"+id).value;
		location.href='?action=editnum&id='+id+'&num='+num;
	}
	function goodsorder(){
		document.form1.action.value="order";
		document.form1.submit();
	}
</script>
<div class="panel panel-inverse">
    <div class="panel-heading">
        <h4 class="panel-title">我的购物车</h4>
    </div>
    <div class="panel-body">
      <form name="form1" method="post" action="mygoodscart.php">

          <TABLE class="table table-bordered table-striped acc-table">
            <THEAD>
              <TR>
                <td><b>商品编号</b></td>
                <td><b>商品名称</b></td>
                <td><b>数量</b></td>
                <td><b>单价</b></td>
                <td><b>操作</b></td>
              </TR>
            </THEAD>
            <input type="hidden" name="chknum" value="0">
            <?
              $goodscartstr=getgoodscart();
              $goodscartary=explode("|",$goodscartstr);
              // var_dump($goodscartary);die();
              if (is_array($goodscartary) && $goodscartary[0] != ''){
              foreach($goodscartary as $key=>$value){
                $items=explode(",",$value);
            ?>
            <TR>
              <TD  id=UltraWebGrid1rc_0_0  level="0_0">
                <? echo $items[0]?>
                <input type="hidden" name="id[]" value="<? echo $items[0]?>">
              </TD>
              <TD  id=UltraWebGrid1rc_0_1  level="0_1">
                <? echo $items[1]?>
              </TD>
              <TD  id=UltraWebGrid1rc_0_2  level="0_2">
                <input id="num_<? echo $items[0]?>" name="num_<? echo $items[0]?>" type="text" value="<? echo $items[2]?>" />
              </TD>
              <TD  id=UltraWebGrid1rc_0_3  level="0_3">
                <? echo $items[3]?>
              </TD>
              <TD align="center"  id=UltraWebGrid1rc_0_4  level="0_4">
                <a href="#" onClick="goodsedit(<? echo $items[0]?>)">修改</a>|<a href="?action=del&id=<? echo $items[0]?>">删除</a>
              </TD>
            </TR>
            <?
              }
              }else{
            ?>
            <TR>
              <TD  id=UltraWebGrid1rc_1_0  level="1_0" colspan="5"></TD>
            </TR>
            <?
              }
            ?>
            <tr>
              <td colspan="4"></td>
              <td>
                <input type="hidden" name="action" value="order">
                  <?php
                    if (is_array($goodscartary) && $goodscartary[0] != ''){
                  ?>
                  <INPUT class="btn btn-success" type="submit"  id="but1" value="确定购物" name="but1">
                  <?php
                    }
                  ?>
              </td>
            </tr>
          </TABLE>
      </form>
    </div>
</div>
